import React from 'react'
import PropTypes from 'prop-types'
import {Input,Form} from 'antd'

 class UpdateForm extends React.Component {
    UpdateForm = React.createRef()

   static propTypes={
        categoryName:PropTypes.string.isRequired,
        setUpdateForm: PropTypes.func.isRequired, // 用来传递form对象的函数 
    }

    state={ }

    UNSAFE_componentWillMount(){
        this.props.setUpdateForm(this.UpdateForm)
    }
    
    // componentDidMount(){
    //  this.setState({categoryName:this.props.categoryName})
    // }

    // UNSAFE_componentWillReceiveProps(nextProps){
    //     const {categoryName} = nextProps
    //    this.setState({categoryName})
    // }

    onValuesChange=(changedValues, allValues)=>{
        this.setState({categoryName:allValues.categoryName})
    }
       
    render() {
        const {categoryName} = this.props
        // const {categoryName} = this.state
        return (
        <Form  ref={this.UpdateForm} onValuesChange={this.onValuesChange} initialValues={{ categoryName }} >
            <Form.Item label="更新类品" required tooltip="不能为空"  name="categoryName">
                <Input placeholder='请输入分类名称'/> 
           </Form.Item>
        </Form>
         
        )
    }
}
export default  UpdateForm
